package gui.comboBoxRenderers;

import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import ukoly.ProjektControl;

/**
 *
 * @author Pavel Lieberzeit
 *

* Tohle je ze Sunovskyho tutorialu na combobox, mirne upraveno. Renderuje projektComboBox
*/
public class ProjektComboBoxRenderer extends JLabel implements ListCellRenderer {

    public ProjektComboBoxRenderer() {
        setOpaque(true);
        setHorizontalAlignment(CENTER);
        setVerticalAlignment(CENTER);
    }

    /*
     * This method finds the image and text corresponding
     * to the selected value and returns the label, set up
     * to display the text and image.
     */
    @Override
    public Component getListCellRendererComponent(
                                       JList list,
                                       Object value,
                                       int index,
                                       boolean isSelected,
                                       boolean cellHasFocus) {
        //Get the selected index. (The index param isn't
        //always valid, so just use the value.)

        if (isSelected) {
            setBackground(list.getSelectionBackground());
            setForeground(list.getSelectionForeground());
        } else {
            setBackground(list.getBackground());
            setForeground(list.getForeground());
        }


        if(value == null)
            this.setText(" ");
        //TODO: REMOVE THIS! nah, screw it
        else if(value instanceof String)
            this.setText((String)value);
        else  {
            this.setText(((ProjektControl)value).getModel().getJmeno());
            this.setToolTipText(((ProjektControl)value).getModel().getJmeno());
        }

        return this;           
    }
}
